﻿using System;
using System.Net;
using System.Xml.Linq;
using System.Linq;
using System.Collections.Generic;

namespace ArmoryBrowser.Entities
{
    public class CharacterTab
    {
        #region Fields
        private string _buffsField;
        private string _debuffsField;
        private TalentSpec[] _talentSpecsField;
        private Pvp _pvpField;
        private ProfessionsSkill[] _professionsField;
        private CharacterBars _characterBarsField;
        private BaseStats _baseStatsField;
        private Resistances _resistancesField;
        private Melee _meleeField;
        private Ranged _rangedField;
        private Spell _spellField;
        private Defenses _defensesField;
        private ItemsCollection _itemsField;
        private Glyph[] _glyphsField;
        #endregion
        #region Properties
        public string Buffs
        {
            get
            {
                return this._buffsField;
            }
            set
            {
                this._buffsField = value;
            }
        }

        public string Debuffs
        {
            get
            {
                return this._debuffsField;
            }
            set
            {
                this._debuffsField = value;
            }
        }

        public TalentSpec[] TalentSpecs
        {
            get
            {
                return this._talentSpecsField;
            }
            set
            {
                this._talentSpecsField = value;
            }
        }

        public Pvp Pvp
        {
            get
            {
                return this._pvpField;
            }
            set
            {
                this._pvpField = value;
            }
        }

        public ProfessionsSkill[] Professions
        {
            get
            {
                return this._professionsField;
            }
            set
            {
                this._professionsField = value;
            }
        }

        public CharacterBars CharacterBars
        {
            get
            {
                return this._characterBarsField;
            }
            set
            {
                this._characterBarsField = value;
            }
        }

        public BaseStats BaseStats
        {
            get
            {
                return this._baseStatsField;
            }
            set
            {
                this._baseStatsField = value;
            }
        }

        public Resistances Resistances
        {
            get
            {
                return this._resistancesField;
            }
            set
            {
                this._resistancesField = value;
            }
        }

        public Melee Melee
        {
            get
            {
                return this._meleeField;
            }
            set
            {
                this._meleeField = value;
            }
        }

        public Ranged Ranged
        {
            get
            {
                return this._rangedField;
            }
            set
            {
                this._rangedField = value;
            }
        }

        public Spell Spell
        {
            get
            {
                return this._spellField;
            }
            set
            {
                this._spellField = value;
            }
        }

        // TODO : No hecho
        public Defenses Defenses
        {
            get
            {
                return this._defensesField;
            }
            set
            {
                this._defensesField = value;
            }
        }

        public ItemsCollection Items
        {
            get
            {
                return this._itemsField;
            }
            set
            {
                this._itemsField = value;
            }
        }

        public Glyph[] Glyphs
        {
            get
            {
                return this._glyphsField;
            }
            set
            {
                this._glyphsField = value;
            }
        }
        #endregion
        #region Constructor
        public CharacterTab(XElement element)
        {
            Buffs = element.GetAttributeValue("buffs");
            Debuffs = element.GetAttributeValue("debuffs");
            TalentSpecs = element.Elements("talentSpecs").Select(e => e.Elements("talentSpec").Select(e2 => new TalentSpec(e2)).ToArray()).FirstOrDefault();
            Pvp = element.Elements("pvp").Select(e => new Pvp(e)).FirstOrDefault();
            Professions = element.Elements("professions").Select(e => e.Elements("skill").Select(e2 => new ProfessionsSkill(e2)).ToArray()).FirstOrDefault();
            CharacterBars = element.Elements("characterBars").Select(e => new CharacterBars(e)).FirstOrDefault();
            BaseStats = element.Elements("baseStats").Select(e => new BaseStats(e)).FirstOrDefault();
            Resistances = element.Elements("resistances").Select(e => new Resistances(e)).FirstOrDefault();
            Melee = element.Elements("melee").Select(e => new Melee(e)).FirstOrDefault();
            Ranged = element.Elements("ranged").Select(e => new Ranged(e)).FirstOrDefault();
            Spell = element.Elements("spell").Select(e => new Spell(e)).FirstOrDefault();
            Defenses = element.Elements("defenses").Select(e => new Defenses(e)).FirstOrDefault();
            Items = new ItemsCollection(element.Elements("items").Select(e => e.Elements("item").Select(e2 => new Item(e2)).ToArray()).FirstOrDefault());
            Glyphs = element.Elements("glyphs").Select(e => e.Elements("glyph").Select(e2 => new Glyph(e2)).ToArray()).FirstOrDefault();
        }
        #endregion
    }
}
